﻿using System.Windows;
using ff14bot.Enums;
using ff14bot.Managers;
using System.Linq;
using TreeSharp;
using Magitek.Helpers;
using ff14bot;
using ff14bot.Objects;
using ff14bot.Behavior;

namespace Magitek.Rotations
{
    public class Paladin : Magitek
    {
        public override float PullRange { get { return WindowSettings.PaladinPullRange; } }
        public override ClassJobType[] Class { get { return new ClassJobType[] { ClassJobType.Paladin }; } }
        #region Pulling & Resting
        protected override Composite CreatePull()
        {
            return Combat.CreatePull(4);
        }

        protected override Composite CreateRest()
        {
            return Extensions.DefaultRestBehavior(r => Core.Player.CurrentManaPercent);
        }
        #endregion
        #region Buffs // Mainly used for Grindbot etc...

        protected override Composite CreatePreCombatBuffs()
        {
            return new PrioritySelector(
                Extensions.SummonChocobo()
                );
        }

        protected override Composite CreateCombatBuffs()
        {
            return new PrioritySelector(

            );
        }
        #endregion
        #region Combat
        protected override Composite CreateHeal()
        {
            return new PrioritySelector(
                Casting.Cast(r => "Hallowed Ground", r => Core.Player.CurrentHealthPercent <= WindowSettings.PaladinUseHallowedGroundHpPercent && WindowSettings.PaladinUseHallowedGround, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Sentinel", r => Core.Player.CurrentHealthPercent <= WindowSettings.PaladinUseSentinelHpPercent, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Foresight", r => Core.Player.CurrentHealthPercent <= WindowSettings.PaladinUseForesightHpPercent, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Rampart", r => Core.Player.CurrentHealthPercent <= WindowSettings.PaladinUseRampartHpPercent, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Convalescence", r => Core.Player.CurrentHealthPercent <= WindowSettings.PaladinUseConvalescenceHpPercent, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Bulwark", r => Core.Player.CurrentHealthPercent <= WindowSettings.PaladinUseBulwarkHpPercent, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Awareness", r => Core.Player.CurrentHealthPercent <= WindowSettings.PaladinUseAwarenessHpPercent, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Tempered Will", r => WindowSettings.PaladinUseTemperedWill && Core.Player.HasAura("Bind") || Core.Player.HasAura("Heavy"), r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Cure", r => WindowSettings.PaladinUseCure && Core.Player.CurrentHealthPercent <= WindowSettings.PaladinUseCureHp, r => Core.Player, r => 2, r => false));
        }
        public override Composite OnTreeSharpPulse()
        {
            return new PrioritySelector(
                
                new Decorator(r => Core.Player.InCombat || Core.Player.IsDead || Core.Player.IsMounted || !Core.Player.IsValid, new ActionAlwaysSucceed()),

                    new Decorator(r => WindowSettings.PaladinUseShieldOath && !Core.Player.HasAura("Shield Oath"), new Action(r => Actionmanager.DoAction("Shield Oath", Core.Player))),
                    new Decorator(r => !WindowSettings.PaladinUseShieldOath && !Core.Player.HasAura("Sword Oath"), new Action(r => Actionmanager.DoAction("Sword Oath", Core.Player))),
					Items.Use(WindowSettings.foodname, true)

                );
        }
        protected override Composite CreateCombat()
        {
            return new PrioritySelector(ctx => Core.Player.CurrentTarget,
                new Decorator(ctx => ctx != null,
                new PrioritySelector(
                new Decorator(ctx => ctx != null && BotManager.Current.IsAutonomous,
                    new PrioritySelector(
                        CommonBehaviors.MoveToLos(ctx => ctx as GameObject),
                        CommonBehaviors.MoveAndStop(ctx => (ctx as GameObject).Location, ctx => 3 + (ctx as GameObject).CombatReach, true, "Moving to unit")
						)
					),
               
                PartyHelper.AcquireTargetInformation(),

                Casting.Cast(r => "Spirits Within", r => WindowSettings.InterruptCast && Combat.CheckForInterrupt() && WindowSettings.PaladinUseSpiritsWithinOnlyToInterrupt, r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Shield Bash", r => WindowSettings.InterruptCast && Combat.CheckForInterrupt(), r => Core.Player.CurrentTarget, r => 2, r => false),

                Combat.DoPVP(),

                Casting.Cast(r => "Cover", r => WindowSettings.PaladinUseCover && PartyHelper.Covertarget != null, r => PartyHelper.Covertarget, r => 2, r => false),

                #region AOE Mode
                new Decorator(r => WindowSettings.AOEEnabled && Core.Player.CurrentTarget.IsFlanking, new PrioritySelector(
                    Casting.Cast(r => "Circle of Scorn", r => true, r => Core.Player, r => 2, r => false),
                    Casting.Cast(r => "Flash", r => Core.Player.CurrentManaPercent >= WindowSettings.PaladinStopFlashMpPercent, r => Core.Player, r => 2, r => false)
                    )),
                #endregion
                
                Casting.Cast(r => "Bloodbath", r => true, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Fight or Flight", r => true, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Circle of Scorn", r => WindowSettings.PaladinCircleSingle && Core.Player.CurrentTarget.Location.Distance(Core.Player.Location) < 5, r => Core.Player, r => 3, r => true),
                Casting.Cast(r => "Circle of Scorn", r => (Extensions.EnemiesNearTarget(5) >= WindowSettings.TargetsToAOE && Core.Player.CurrentTarget.Location.Distance(Core.Player.Location) < 5 && !WindowSettings._dontaoeList.Contains(Core.Player.CurrentTarget.Name)), r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Flash", r => WindowSettings.PaladinUseFlash && Extensions.EnemiesNearTarget(5) >= WindowSettings.TargetsToAOE && Core.Player.CurrentManaPercent >= WindowSettings.PaladinStopFlashMpPercent && !WindowSettings._dontaoeList.Contains(Core.Player.CurrentTarget.Name), r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Provoke", r => WindowSettings.PaladinUseProvoke && Combat.ProvokeTarget() != null, r => Combat.ProvokeTarget(), r => 2, r => false),
                Casting.Cast(r => "Spirits Within", r => WindowSettings.PaladinUseSpiritsWithin && !WindowSettings.PaladinUseSpiritsWithinOnlyToInterrupt, r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Mercy Stroke", r => true, r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Shield Swipe", r => WindowSettings.PaladinUseShieldSwipe, r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Fracture", r => !Core.Player.CurrentTarget.HasAura("Fracture", true) && WindowSettings.PaladinUseFracture, r => Core.Player.CurrentTarget, r => 2, r => true),
                Casting.Cast(r => "Rage of Halone", r => Actionmanager.LastSpell.Name == "Savage Blade", r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Riot Blade", r => WindowSettings.PaladinUseRiotBlade && Core.Player.CurrentManaPercent < WindowSettings.PaladinUseRiotBladeMpPercent && Actionmanager.LastSpell.Name == "Fast Blade", r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Savage Blade", r => Actionmanager.LastSpell.Name == "Fast Blade", r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Fast Blade", r => true, r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Shield Lob", r => WindowSettings.PaladinUseShieldLob, r => Core.Player.CurrentTarget, r => 2, r => false)
                )));
        }
        #endregion
    }
}
